import { defineStore } from "pinia"
import { getRecommendValueList, getRecAutoValueList } from "../api/api1/recommend"
export const useRecommendStore = defineStore({
  id: 'recommend',
  state: () => {
    return {
      recommendList: [],
      recAutoList: <any>[]
    }
  },
  actions: {
    async getRecommendList() {
      try {
        const result: any = await getRecommendValueList()

        this.recommendList = result.navList
      } catch (error) {
        console.log(error);
      }
    },
    async getRecAutoList(page: number, size: number) {
      try {
        const result: any = await getRecAutoValueList(page, size)

        this.recAutoList.push(...result.result)

      } catch (error) {
        console.log(error);
      }
    }

  },
  getters: {
    toPics() {
      let obj = <any>[];
      this.recAutoList.forEach((item: any) => {

        if (this.recAutoList.length < 0) {
          return []
        } else {
          obj.push(item.look, ...item.topics);
        }
      })

      return obj
    }
  }
})